package com.donger.business.message.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donger.business.message.entity.MessageTemplate;
import com.donger.business.message.service.MessageTemplateService;
import com.donger.common.core.utils.Res;
import com.donger.common.core.utils.Result;
import com.donger.common.query.utils.QueryGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 消息模板管理
 * @author 7326
 */
@RestController
@RequestMapping("/message/template")
@AllArgsConstructor
@Api(tags = "消息模板开发API")
public class MessageTemplateController {
    private final MessageTemplateService messageTemplateService;


    /**
     * 模板分页
     * @param page
     * @param messageTemplate
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询消息模板")
    public Result page(Page page, MessageTemplate messageTemplate){
        QueryWrapper<MessageTemplate> messageTemplateQueryWrapper = QueryGenerator.<MessageTemplate>initQueryWrapper(messageTemplate);
        messageTemplateService.page(page,messageTemplateQueryWrapper);
        return Res.ok(page);
    }

    /**
     * 新增模板
     * @param messageTemplate
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody MessageTemplate messageTemplate){
        messageTemplateService.save(messageTemplate);
        return Res.ok();
    }



}
